home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / libtiff / tif_comp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  4.8 KB  |  174 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_compress.c,v 1.23 91/08/23 17:09:25 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991 Sam Leffler
  7.  * Copyright (c) 1991 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library
  31.  *
  32.  * Compression Scheme Configuration Support.
  33.  */
  34. #include "tiffioP.h"
  35.  
  36. #if USE_PROTOTYPES
  37. extern    int TIFFInitDumpMode(TIFF*);
  38. #ifdef PACKBITS_SUPPORT
  39. extern    int TIFFInitPackBits(TIFF*);
  40. #endif
  41. #ifdef CCITT_SUPPORT
  42. extern    int TIFFInitCCITTRLE(TIFF*), TIFFInitCCITTRLEW(TIFF*);
  43. extern    int TIFFInitCCITTFax3(TIFF*), TIFFInitCCITTFax4(TIFF*);
  44. #endif
  45. #ifdef THUNDER_SUPPORT
  46. extern    int TIFFInitThunderScan(TIFF*);
  47. #endif
  48. #ifdef NEXT_SUPPORT
  49. extern    int TIFFInitNeXT(TIFF*);
  50. #endif
  51. #ifdef LZW_SUPPORT
  52. extern    int TIFFInitLZW(TIFF*);
  53. #endif
  54. #ifdef JPEG_SUPPORT
  55. extern    int TIFFInitJPEG(TIFF*);
  56. #endif
  57. #else
  58. extern    int TIFFInitDumpMode();
  59. #ifdef PACKBITS_SUPPORT
  60. extern    int TIFFInitPackBits();
  61. #endif
  62. #ifdef CCITT_SUPPORT
  63. extern    int TIFFInitCCITTRLE(), TIFFInitCCITTRLEW();
  64. extern    int TIFFInitCCITTFax3(), TIFFInitCCITTFax4();
  65. #endif
  66. #ifdef THUNDER_SUPPORT
  67. extern    int TIFFInitThunderScan();
  68. #endif
  69. #ifdef NEXT_SUPPORT
  70. extern    int TIFFInitNeXT();
  71. #endif
  72. #ifdef LZW_SUPPORT
  73. extern    int TIFFInitLZW();
  74. #endif
  75. #ifdef JPEG_SUPPORT
  76. extern    int TIFFInitJPEG();
  77. #endif
  78. #endif
  79.  
  80. static    struct cscheme {
  81.     char*    name;
  82.     int    scheme;
  83.     int    (*init)();
  84. } CompressionSchemes[] = {
  85.     { "Null",        COMPRESSION_NONE,    TIFFInitDumpMode },
  86. #ifdef LZW_SUPPORT
  87.     { "LZW",        COMPRESSION_LZW,    TIFFInitLZW },
  88. #endif
  89. #ifdef PACKBITS_SUPPORT
  90.     { "PackBits",    COMPRESSION_PACKBITS,    TIFFInitPackBits },
  91. #endif
  92. #ifdef THUNDER_SUPPORT
  93.     { "ThunderScan",    COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
  94. #endif
  95. #ifdef NEXT_SUPPORT
  96.     { "NeXT",        COMPRESSION_NEXT,    TIFFInitNeXT },
  97. #endif
  98. #ifdef JPEG_SUPPORT
  99.     { "JPEG",        COMPRESSION_JPEG,    TIFFInitJPEG },
  100. #endif
  101. #ifdef CCITT_SUPPORT
  102.     { "CCITT RLE",    COMPRESSION_CCITTRLE,    TIFFInitCCITTRLE },
  103.     { "CCITT RLE/W",    COMPRESSION_CCITTRLEW,    TIFFInitCCITTRLEW },
  104.     { "CCITT Group3",    COMPRESSION_CCITTFAX3,    TIFFInitCCITTFax3 },
  105.     { "CCITT Group4",    COMPRESSION_CCITTFAX4,    TIFFInitCCITTFax4 },
  106. #endif
  107. };
  108. #define    NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
  109.  
  110. static struct cscheme *
  111. findScheme(scheme)
  112.     int scheme;
  113. {
  114.     register struct cscheme *c;
  115.  
  116.     for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
  117.         if (c->scheme == scheme)
  118.             return (c);
  119.     return ((struct cscheme *)0);
  120. }
  121.  
  122. int
  123. TIFFNoEncode(tif, pp, cc, s)
  124.     TIFF *tif;
  125.     u_char *pp;
  126.     int cc;
  127.     u_int s;
  128. {
  129.     struct cscheme *c = findScheme(tif->tif_dir.td_compression);
  130.     TIFFError(tif->tif_name, "%s encoding is not implemented", c->name);
  131.     return (-1);
  132. }
  133.  
  134. int
  135. TIFFNoDecode(tif, pp, cc, s)
  136.     TIFF *tif;
  137.     u_char *pp;
  138.     int cc;
  139.     u_int s;
  140. {
  141.     struct cscheme *c = findScheme(tif->tif_dir.td_compression);
  142.     TIFFError(tif->tif_name, "%s decoding is not implemented", c->name);
  143.     return (-1);
  144. }
  145.  
  146. TIFFSetCompressionScheme(tif, scheme)
  147.     TIFF *tif;
  148.     int scheme;
  149. {
  150.     struct cscheme *c = findScheme(scheme);
  151.  
  152.     if (!c) {
  153.         TIFFError(tif->tif_name,
  154.             "Unknown data compression algorithm %u (0x%x)",
  155.             scheme, scheme);
  156.         return (0);
  157.     }
  158.     tif->tif_predecode = NULL;
  159.     tif->tif_decoderow = TIFFNoDecode;
  160.     tif->tif_decodestrip = TIFFNoDecode;
  161.     tif->tif_decodetile = TIFFNoDecode;
  162.     tif->tif_preencode = NULL;
  163.     tif->tif_postencode = NULL;
  164.     tif->tif_encoderow = TIFFNoEncode;
  165.     tif->tif_encodestrip = TIFFNoEncode;
  166.     tif->tif_encodetile = TIFFNoEncode;
  167.     tif->tif_close = NULL;
  168.     tif->tif_seek = NULL;
  169.     tif->tif_cleanup = NULL;
  170.     tif->tif_flags &= ~TIFF_NOBITREV;
  171.     tif->tif_options = 0;
  172.     return ((*c->init)(tif));
  173. }
  174.